package com.bruce.common.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * 软键盘工具类
 * @author LiXiaoLong
 * @since 2013年11月19日下午2:34:08
 * @version 1.0
 */
public class KeyboardUtil {
	/**
	 * 隐藏软键盘
	 * @param acti Activity
	 */
	public static void hideKeyboard(Activity acti) {
		if (acti == null)
			return;
		final View v = acti.getWindow().peekDecorView();
		if (v != null && v.getWindowToken() != null) {
			InputMethodManager imm = (InputMethodManager) acti
					.getSystemService(Context.INPUT_METHOD_SERVICE);
			imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
		}
	}
	
	/**
	 * 软键盘是否打开
	 * @param acti 当前activity
	 * @return 状态
	 */
	public static boolean isShowing(Activity acti) {
		InputMethodManager imm = (InputMethodManager) acti
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		return imm.isActive();
	}
}
